package com.zzyl.controller.web;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 护理项目表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-15
 */
@RestController
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    //分页条件查询
    @GetMapping("//nursing_project")
    public ResponseResult getByPage(String name, Integer status,
                                     @RequestParam(defaultValue = "1")Integer pageNum,
                                     @RequestParam(defaultValue = "10")Integer pageSize){
        PageResponse<NursingProject>pageResponse=nursingProjectService.getByPage(name,status,pageNum,pageSize);
        return ResponseResult.success(pageResponse);
    }

    //新增护理项目
    @PostMapping("/nursing_project")
    public ResponseResult save(@RequestBody NursingProject nursingProject){
        nursingProjectService.save(nursingProject);
        return ResponseResult.success();
    }

    //根据id查询
    @GetMapping("/nursing_project/{id}")
    public ResponseResult getById(@PathVariable("id")Long id){
        NursingProject nursingProject = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProject);
    }

    //修改护理项目
    @PutMapping("/nursing_project/{id}")
    public ResponseResult update(@RequestBody NursingProject nursingProject){
        nursingProjectService.updateById(nursingProject);
        return ResponseResult.success();
    }

    //修改状态 0禁用 1启用
    @PutMapping("/nursing_project/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable("id")Long id,
                                       @PathVariable("status")Integer status){
        NursingProject nursingProject=new NursingProject();
        nursingProject.setId(id);
        nursingProject.setStatus(status);
        nursingProjectService.updateById(nursingProject);
        return ResponseResult.success();
    }

    //根据id删除护理项目
    @DeleteMapping("/nursing_project/{id}")
    public ResponseResult delete(@PathVariable("id")Long id){
        //todo 如果护理项目被护理计划使用  不能被删除
        nursingProjectService.removeById(id);
        return ResponseResult.success();
    }

    //直接查询所有(其他功能使用
    @GetMapping("/nursing_project/all")
    public ResponseResult getAll(){
        List<NursingProject> list = nursingProjectService.list();
        return ResponseResult.success(list);
    }

}
